<?php
    require_once(dirname(__FILE__).'/../http/HttpHelper.php');
    class mobilerecharge
    {
        private $boc = 'shanxi';
        private $salt = 'SNXYZ';
        /*生成签名
        *@param string $boc 标识
        *@param string $mobile 手机号
        *@param string $sporder_id 订单单号
        *@param int $cardnum 订单金额
        *@param string $cardid 商品编码
        */
        private function createSign($game_userid,$sporder_id,$cardnum,$cardid)
        {
            $sign = md5($this->boc.$sporder_id.$cardnum.$game_userid.$cardid.$this->salt);
            return $sign;
        }
        /*校验sign*/
        public function checkSign($game_userid='',$sporder_id='',$cardnum='',$cardid='',$sign='')
        {
            if(empty($game_userid) || empty($sporder_id) || empty($cardnum) || empty($cardid) || empty($sign))
            {
                return false;
            }
            /*生成sign*/
            $signcheck = $this->createSign($game_userid,$sporder_id,$cardnum,$cardid);
            if($signcheck == $sign)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /*手机充值*/
        public function payorder($game_userid,$sporder_id,$cardnum,$cardid,$sporder_time)
        {
            /*sign*/
            $sign = $this->createSign($game_userid,$sporder_id,$cardnum,$cardid);
            /*支付地址*/
            $url = "http://oufeiapi.snrunning.cn/onlineorder.php?act=mobilerecharge";
            //$url = "http://pmw.com/port/oufei/onlineorder.php?act=mobilerecharge";
            /*支付参数*/
            $data = array(
                'boc'=>$this->boc,
                'game_userid'=>$game_userid,
                'cardnum'=>$cardnum,
                'sporder_id'=>$sporder_id,
                'cardid'=>$cardid,
                'sporder_time'=>$sporder_time,
                'sign'=>$sign,
                'userid'=>'A08566',
                'userpws'=>md5('of111111'),
                'key_str'=>'OFCARD',
                'ret_url'=>'http://nas.snrunning.cn/member/sn_app_card_20190301/rechargeback.php',
                'remark'=>'陕西中行手机测试充值'
            );
            $res = HttpHelper::curl($url,'POST',$data);
            return $res;
        }
    }